import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import legacy from '@vitejs/plugin-legacy'

// https://vitejs.dev/config/
export default defineConfig({
	plugins: [
		legacy({
			targets: ['chrome 52'], // 需要兼容的目标列表，可以设置多个
      		additionalLegacyPolyfills: ['regenerator-runtime/runtime'], // 面向IE11时需要此插件
			//targets: ['defaults', 'not IE 11'],
		}),
		vue(),		
	],
	
	server: {
		host: '0.0.0.0',
		hmr: true,
	},
	base: './',
	build: {
		target: 'ES2015',
		/* sourcemap: true,
		rollupOptions: {
		output: {
			sourcemap: true,
		},
		} */
	},
	resolve: {
		alias: {
			'@': fileURLToPath(new URL('./src', import.meta.url)),
		}
	},
	css: {
		postcss: {
			plugins: [
				{
					postcssPlugin: 'internal:charset-removal',
					AtRule: {
						charset: (atRule) => {
							if (atRule.name === 'charset') {
								atRule.remove()
							}
						},
					},
				},
			],
		},
	},
})
